package com.bryantkobe.myspringcode.config;

import io.swagger.v3.oas.annotations.enums.SecuritySchemeIn;
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType;
import io.swagger.v3.oas.annotations.security.SecurityScheme;
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @description: springdoc文档配置类
 * @author: alienwarezzl
 * @date: 2025/3/30
 */
@Configuration
@SecurityScheme(
        name = "Authorization",
        type = SecuritySchemeType.HTTP,
        scheme = "bearer",
        bearerFormat = "JWT",
        in = SecuritySchemeIn.HEADER)
public class SpringDocConfig {

    @Bean
    public OpenAPI springOpenAPI(){
        return new OpenAPI()
                .info(new Info()
                        .title("My Spring Code")
                        .description("My Spring项目文档")
                        .version("v1.0.0")
                .license(new License()
                        .name("Apache 2.0")
                        .url("https://www.apache.org/licenses/LICENSE-2.0.html")))
                .externalDocs(new ExternalDocumentation()
                        .description("My Spring Code")
                        .url("alienwarezzl@outlook.com"));
    }

    /*@Bean
    public GroupedOpenApi helloApi() {
        return GroupedOpenApi.builder()
                .displayName("初始接口")
                .group("hello")
                .packagesToScan("com.bryantkobe.myspringcode.controller")
                .addOpenApiCustomizer(openApiCustomiser())
                .addOperationCustomizer(operationCustomizer())
                .build();
    }

    public OpenApiCustomizer openApiCustomiser() {
        return api ->
                api.components(new Components()
                        .addSecuritySchemes("Authorization", new SecurityScheme()
                                .name("认证")
                                .type(SecurityScheme.Type.HTTP)
                                .description("JWT认证")
                                .scheme("bearer")
                                .bearerFormat("JWT"))
                );
    }

    public OperationCustomizer operationCustomizer() {
        return (operation, handlerMethod) -> {
            operation.addSecurityItem(new SecurityRequirement().addList("Authorization"));
            return operation;
        };
    }*/

}
